//
//  ListViewController.m
//  FrameWork2.0
//
//  Created by jiaming yan on 16/7/26.
//  Copyright © 2016年 yanjiaming. All rights reserved.
//

#import "ListViewController.h"
#import "OrderDemoVC.h"
#import "EmojiVC.h"
#import "StarRatingVC.h"
#import "YJMGuideViewManager.H"
#import "BannerVC.h"
#import "AFURLSessionManager.h"
#import "MJRefresh.h"
#import "MsonryVC.h"
#import "CusTabbleViewVC.h"
#import "MyShapeLayerVC.h"
#import "EncryptionVC.h"
#import "CitySelectedVC.h"
@interface ListViewController ()<UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic)  NSArray *arrData;//图片名数组
@end

@implementation ListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.arrData = @[@"订单切页面:OrderDemo",@"自定义表情键盘EmojiVC",@"评价星级StarRatingVC",@"引导页面",@"滚动广告、查看多图BannerVC",@"网络post请求",@"文件上传",@"Masonry",@"列表cell自适应",@"饼状图",@"加密算法",@"城市选择"];
    

//    NSMutableArray *images = [NSMutableArray new];
//
//    [images addObject:[UIImage imageNamed:@"welcom1"]];
//    [images addObject:[UIImage imageNamed:@"welcom2"]];
//    [images addObject:[UIImage imageNamed:@"welcom3"]];
//    [images addObject:[UIImage imageNamed:@"welcom4"]];
//    /****考虑到app包大小问题，以后引导页面切图只切6p或者6的图，程序中会对图片进行裁剪。所以设计的时候需要对内容部分进行分割设计，顶部和底部只是用纯色来填充，立即体验的按钮可以看情况是放到图中还是自己的，如果是图片中的需要全部clear颜色，然后放大按钮位置****/
//
//    /****所以这种情况下必须设计做的时候需要随时沟通，做完一张就需要测试后才往下设计****/
//    [[YJMGuideViewManager sharedInstance] showGuideViewWithImages:images
//                                                   andButtonTitle:@"立即体验"
//                                              andButtonTitleColor:[UIColor whiteColor]
//                                                 andButtonBGColor:[UIColor clearColor]
//                                             andButtonBorderColor:[UIColor whiteColor]];
    
    [self downRefreshRequest];
    [self upRefreshRequest];
    
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.arrData.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
    }
   
    cell.textLabel.text = self.arrData[indexPath.row];
    
    return cell;
}
- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            OrderDemoVC *vc = [[OrderDemoVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            EmojiVC *vc = [[EmojiVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            StarRatingVC *vc = [[StarRatingVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:
        {
            BannerVC *vc = [[BannerVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 5:
        {
            //GCD执行耗时操作
            [self showProgressWithView:self.view animated:YES];
            [SendRequest common_orientation_With_result:^(id result, NSError *error){
                [self hideProgress:self.view animated:YES];
                SaintiLog(@"%@",result);
            }];


        }
            break;
        case 6:
        {
            NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"测试" ofType:@"jpg"]];
            NSArray *dataArr = [NSArray arrayWithObjects:data,data, nil];
            //GCD执行耗时操作
            [SendRequest uploadWithFileDatas:dataArr result:^(id result, NSError *error){
              
                /**请把测试这张图片删除。务必*/
                [[CommonUtils sharedCommonUtils]showAlert:@"请把测试这张图片删除。务必" delegate:nil ];
            }];
            
            
        }
            break;
        case 7:
        {
            MsonryVC *vc = [[MsonryVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 8:
        {
            CusTabbleViewVC *vc = [[CusTabbleViewVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 9:
        {
            MyShapeLayerVC *vc = [[MyShapeLayerVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 10:
        {
            EncryptionVC *vc = [[EncryptionVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 11:
        {
            CitySelectedVC *vc = [[CitySelectedVC alloc]init];
            vc.citySelected = ^(NSString *cityName,NSString *cityId){
                SaintiLog(@"%@---%@",cityId,cityName);
            };
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}
#pragma mark -
#pragma mark 下拉刷新
- (void)downRefreshRequest //内部方法改
{
    //    __block MyFolderVC *business = self;
    __weak typeof(self) weakSelf = self;
    MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            self.arrData = @[@"订单切页面:OrderDemo",@"自定义表情键盘EmojiVC",@"评价星级StarRatingVC",@"引导页面",@"滚动广告、查看多图BannerVC",@"网络post请求",@"文件上传"];
            sleep(3);
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableView reloadData];
                
                if (weakSelf.arrData.count < 1) {
                    [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
                    
                }else{
                    [weakSelf.tableView.mj_footer endRefreshing];
                }
                [weakSelf.tableView.mj_header endRefreshing];
            });
            
        });
            }];
       MJHEADER;
    [header setImages:     @[IMAGE(@"图层-1"),IMAGE(@"图层-2"),IMAGE(@"图层-3"),IMAGE(@"图层-4"),IMAGE(@"图层-5"),IMAGE(@"图层-6"),IMAGE(@"图层-7"),IMAGE(@"图层-8"),IMAGE(@"图层-9"),IMAGE(@"图层-10"),IMAGE(@"图层-11"),IMAGE(@"图层-13"),IMAGE(@"图层-14"),IMAGE(@"图层-15"),IMAGE(@"图层-16"),IMAGE(@"图层-17"),IMAGE(@"图层-18"),IMAGE(@"图层-19"),IMAGE(@"图层-20"),IMAGE(@"图层-21"),IMAGE(@"图层-22"),IMAGE(@"图层-23"),IMAGE(@"图层-24"),IMAGE(@"图层-25"),IMAGE(@"图层-26"),IMAGE(@"图层-27"),IMAGE(@"图层-28"),IMAGE(@"图层-29"),IMAGE(@"图层-30"),IMAGE(@"图层-31"),IMAGE(@"图层-32"),IMAGE(@"图层-33"),IMAGE(@"图层-34"),IMAGE(@"图层-35"),IMAGE(@"图层-36"),IMAGE(@"图层-37"),IMAGE(@"图层-38"),IMAGE(@"图层-39"),IMAGE(@"图层-40"),IMAGE(@"图层-41"),IMAGE(@"图层-42"),IMAGE(@"图层-43"),IMAGE(@"图层-44"),IMAGE(@"图层-45"),IMAGE(@"图层-46"),IMAGE(@"图层-47"),IMAGE(@"图层-48"),IMAGE(@"图层-49"),IMAGE(@"图层-50"),IMAGE(@"图层-51")]  forState:MJRefreshStateIdle];

 
    self.tableView.mj_header = header;
    
}
#pragma mark 上拉加载
- (void)upRefreshRequest //内部方法改
{
    __weak typeof(self) weakSelf = self;
    
    MJRefreshBackGifFooter *footer = [MJRefreshBackGifFooter footerWithRefreshingBlock:^{
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSMutableArray *arr = [NSMutableArray arrayWithArray:self.arrData];
            [arr addObjectsFromArray:self.arrData];
            self.arrData = arr;
            sleep(3);
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableView reloadData];
                
                [weakSelf.tableView.mj_footer endRefreshing];
            });
            
        });
        
        
    }];
    
    MJFOOTER;
    self.tableView.mj_footer = footer;
    
    
    //    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
    //        if (weakSelf.arrFolder.count > 0) {
    //            [weakSelf upRefreshRequestFloderData];
    //        }else{
    //            [weakSelf sendRequestFloder];
    //            [weakSelf.tableView.mj_footer endRefreshing];
    //        }
    //    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
